﻿// Copyright (c)  MOKEYISH. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Collections.Generic;

namespace NSQL.LogicalResource
{
    public class LogicalTable : ILogicalTable
    {
        private readonly List<ILogicalColumn> _columns = new List<ILogicalColumn>();
        public ILogicalDatabase Database => Schema?.Database;
        public ILogicalSchema Schema { get; set; }
        public int Id { get; set; }
        public string Name { get; set; }
        public string Expr { get; set; }
        public IReadOnlyList<ILogicalColumn> Columns => _columns;
        public void Add(ILogicalColumn column) => _columns.Add(column);

        public void Add(LogicalColumn column)
        {
            column.Table = this;
            _columns.Add(column);
        }
        public void AddRange(params LogicalColumn[] columns)
        {
            foreach (var column in columns)
            {
                Add(column);
            }
        }
    }
}